<?php 
//server.php 服务端  
set_time_limit(0); 
$filename = './data.txt'; 
 
//模拟新消息到来 
if (!empty($_POST['message'])) { 
    file_put_contents($filename, $_POST['message']); 
    echo 1;
    exit(0); 
} 
 
$old = filemtime($filename); 
$cur = filemtime($filename); 
 
while ( $cur <= $old) { 
    usleep(500000);//休息500ms 
    clearstatcache(); 
    $cur = filemtime($filename); 
} 
 
echo file_get_contents($filename);
